package com.easylinkin.linkappapi.quality.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.quality.dto.QualityAppraisingExcellentDTO;
import com.easylinkin.linkappapi.quality.entity.QualityAppraisingExcellent;
import com.easylinkin.linkappapi.quality.service.QualityAppraisingExcellentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * <p>
 * 质量评优信息 前端控制器
 * </p>
 *
 * @author Xiaoyang
 * @since 2022-09-01
 */
@RestController
@RequestMapping("/quality/qualityAppraisingExcellent")
@Api(tags = "质量评优信息管理")
public class QualityAppraisingExcellentController {

  @Autowired
  private QualityAppraisingExcellentService qualityAppraisingExcellentService;

  /**
   * 新增数据
   *
   * @param qualityAppraisingExcellent 实体对象
   * @return 新增结果
   */
  @PostMapping
  @ApiOperation("新增")
  public RestMessage insert(@RequestBody QualityAppraisingExcellent qualityAppraisingExcellent) {
    Assert.hasLength(qualityAppraisingExcellent.getImgs(), "照片不能为空");
    Assert.notNull(qualityAppraisingExcellent.getProblemTypeId(), "评优分类不能为空");
    Assert.notNull(qualityAppraisingExcellent.getCheckPartId(), "施工部位不能为空");
    Assert.notNull(qualityAppraisingExcellent.getAppraisingTime(), "评优时间不能为空");
    return RestBuilders.successBuilder().success((qualityAppraisingExcellentService.saveOne(qualityAppraisingExcellent))).build();
  }

  /**
   * 分页查询所有数据
   *
   * @param requestModel 查询分页对象
   * @return 所有数据
   */
  @PostMapping("/selectDtoPage")
  @ApiOperation("评优列表")
  public RestMessage selectDtoPage(@RequestBody RequestModel<QualityAppraisingExcellentDTO> requestModel) {
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<QualityAppraisingExcellentDTO> record = qualityAppraisingExcellentService.selectDtoPage(requestModel.getPage(), requestModel.getCustomQueryParams());
    return RestBuilders.successBuilder(record).build();
  }

  /**
   * 根据id查询评优详情
   *
   * @param id
   * @return
   */
  @GetMapping("{id}")
  @ApiOperation("根据id查询评优详情")
  public RestMessage findById(@PathVariable("id")Long id) {
    Assert.notNull(id,"id不能为空");
    QualityAppraisingExcellentDTO dto = qualityAppraisingExcellentService.findById(id);
    return RestBuilders.successBuilder().data(dto).build();
  }


}
